.TH std::ranges::views::take_while,std::ranges::take_while_view 3 "2024.06.10" "http://cppreference.com" "C++ Standard Libary"
.SH NAME
std::ranges::views::take_while,std::ranges::take_while_view \- std::ranges::views::take_while,std::ranges::take_while_view

.SH Synopsis
   Defined in header <ranges>
   template< ranges::view V, class Pred >

       requires ranges::input_range<V> &&
                std::is_object_v<Pred> &&
                std::indirect_unary_predicate<const Pred,             \fB(1)\fP \fI(since C++20)\fP
   ranges::iterator_t<V>>
   class take_while_view

       : public ranges::view_interface<take_while_view<V, Pred>>
   namespace views {

       inline constexpr /*unspecified*/ take_while = /*unspecified*/; \fB(2)\fP \fI(since C++20)\fP

   }
   Call signature
   template< ranges::viewable_range R, class Pred >

       requires /* see below */                                           \fI(since C++20)\fP

   constexpr ranges::view auto take_while( R&& r, Pred&& pred );
   template< class Pred >                                                 \fI(since C++20)\fP
   constexpr /*range adaptor closure*/ take_while( Pred&& pred );

   1) A range adaptor that represents view of the elements from an underlying sequence,
   starting at the beginning and ending at the first element for which the predicate
   returns false.
   2) RangeAdaptorObject. The expression views::take_while(e, f) is
   expression-equivalent to take_while_view(e, f) for any suitable subexpressions e and
   f.

   take_while_view models the concepts contiguous_range, random_access_range,
   bidirectional_range, forward_range, and input_range when the underlying view V
   models respective concepts.

.SH Member functions

   constructor   constructs a take_while_view
   (C++20)       \fI(public member function)\fP
   base          returns a copy of the underlying (adapted) view
   (C++20)       \fI(public member function)\fP
   pred          returns a reference to the stored predicate
   (C++20)       \fI(public member function)\fP
   begin         returns an iterator to the beginning
   (C++20)       \fI(public member function)\fP
   end           returns a sentinel representing the end
   (C++20)       \fI(public member function)\fP
         Inherited from std::ranges::view_interface
   empty         returns whether the derived view is empty. Provided if it satisfies
   (C++20)       sized_range or forward_range.
                 \fI(public member function of std::ranges::view_interface<D>)\fP
   cbegin        returns a constant iterator to the beginning of the range.
   (C++23)       \fI(public member function of std::ranges::view_interface<D>)\fP
   cend          returns a sentinel for the constant iterator of the range.
   (C++23)       \fI(public member function of std::ranges::view_interface<D>)\fP
   operator bool returns whether the derived view is not empty. Provided if
   (C++20)       ranges::empty is applicable to it.
                 \fI(public member function of std::ranges::view_interface<D>)\fP
   data          gets the address of derived view's data. Provided if its iterator type
   (C++20)       satisfies contiguous_iterator.
                 \fI(public member function of std::ranges::view_interface<D>)\fP
   front         returns the first element in the derived view. Provided if it
   (C++20)       satisfies forward_range.
                 \fI(public member function of std::ranges::view_interface<D>)\fP
   operator[]    returns the n^th element in the derived view. Provided if it satisfies
   (C++20)       random_access_range.
                 \fI(public member function of std::ranges::view_interface<D>)\fP

   Deduction guides

   Nested classes

   sentinel the sentinel type
            (exposition-only member class template*)

.SH Example


// Run this code

 #include <iostream>
 #include <ranges>

 int main()
 {
     for (int year : std::views::iota(2020)
                   | std::views::take_while([](int y) { return y <= 2023; }))
         std::cout << year << ' ';
     std::cout << '\\n';

     const char idea[] {"Today is yesterday's tomorrow!..."};
     for (char x : std::ranges::take_while_view(idea, [](char c) { return c != '.'; }))
         std::cout << x;
     std::cout << '\\n';
 }

.SH Output:

 2020 2021 2022 2023
 Today is yesterday's tomorrow!

.SH See also

   ranges::take_view       a view consisting of the first N elements of another view
   views::take             \fI(class template)\fP (range adaptor object)
   (C++20)
   ranges::drop_while_view a view consisting of the elements of another view, skipping
   views::drop_while       the initial subsequence of elements until the first element
   (C++20)                 where the predicate returns false
                           \fI(class template)\fP (range adaptor object)
